package com.yongchun.commons.enums;


import com.yongchun.commons.exceptions.ExceptionEnum;

/**
 * 基础异常接口
 */

public enum BusinessExceptionEnum implements ExceptionEnum {


    SYSTEM_ERROR(-9990, "system.error", "系统异常"),
    NOT_FIND_PAGE(4040, "not.find.page", "该网页无法打开"),
    DAO_GET_ERROR(10000, "dao.get.error", "查无数据"),
    DAO_INSERT_ERROR(10050, "dao.insert.error", "添加数据出错"),
    DAO_INSERT_OVER(10060, "dao.insert.over", "添加数据超过限制条数"),
    DAO_UPDATE_ERROR(10100, "dao.update.error", "更新数据出错"),
    PARAM_DATA_ERROR(10110, "param.data.error", "参数有误"),
    DAO_DEL_ERROR(10150, "dao.del.error", "删除数据出错"),
    DAO_LIST_ERROR(10200, "dao.list.error", "列表数据出错"),
    DAO_LIST_COUNT_ERROR(11250, "dao.list.count.error", "列表记录数出错"),
    OBJ_NULL_ERROR(11280, "obj.null.error", "对象空"),
    EMPTY_ERROR(11290, "empty.error", "空字符"),

    FILE_TYPE_ERR(20110, "file_type_err", "文件类型错误"),

    TOKEN_NULL(1039, "token.null", "token不存在或过期"),
    NOT_LOGIN(30110, "file.type.err", "用户未登录"),

    USERNAME_IS_NULL(40110, "username.is.null", "用户名为空"),
    PASSWORD_IS_NULL(40111, "username.is.null", "密码为空"),
    ADMIN_IS_NULL(40112, "admin.is.null", "用户不存在"),
    PASSWORD_IS_ERROR(40113, "password.is.error", "密码错误"),
    PASSWORD_IS_NOT_SAME(40114, "password.is.not.same", "两次密码不一致"),
    PHONE_IS_NULL(40115, "phone.is.null", "手机号为空"),
    ADMIN_IS_EXIST(40120, "admin.is.exist", "管理员已存在"),

    PHONE_NUMBER_ERROR(40116, "phone.number.error", "手机号有误"),
    VERIFY_CODE_IS_NULL(40117, "verify.code.is.null", "验证码不能为空"),
    VERIFY_CODE_TIME_OUT(40118, "verify.code.time.out", "验证码已过期"),
    PHONE_CODE_ERROR(40119, "phone.code.error", "验证码不正确"),

    PROJECT_DETECT_STATUS_ERROR(50000, "project.detect.status.error", "检测项目状态有误"),
    ALLOT_PROJECT_ITEM_NUM_EMPTY(50000, "allot.project.item.num.empty", "请选择分配项目"),


    PROJECT_KEY_EMPTY_ERROR(80000, "project.key.empty.error", "接收项目数据缺少主键"),
    PROJECT_ITEM_EMPTY_ERROR(81000, "project.item.empty.error", "样品的检测项目为空"),
    PROJECT_ITEM_MATCH_ERROR(82000, "project.item.match.error", "样品的检测项目不匹配"),

    CHANGE_ID_ERROR(92000, "change.id.error", "转换id有误"),


    ;


    private int code;
    private String key;
    private String message;

    BusinessExceptionEnum(int code, String key, String message) {
        this.code = code;
        this.key = key;
        this.message = message;
    }

    public static String getMessageFromCode(int code) {

        for (BusinessExceptionEnum business : BusinessExceptionEnum.values()) {
            if (code == business.getCode())
                return business.getMessage();
        }

        return "";

    }

    public static BusinessExceptionEnum getBusiness(int code) {
        for (BusinessExceptionEnum business : BusinessExceptionEnum.values()) {
            if (code == business.getCode())
                return business;
        }
        return null;
    }

    public static BusinessExceptionEnum getBusiness(String key) {
        for (BusinessExceptionEnum business : BusinessExceptionEnum.values()) {
            if (key == business.getKey())
                return business;
        }
        return null;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
